package my;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import vo.person;

import com.opensymphony.xwork2.ActionSupport;

import dao.persondao;

public class PersonAction extends ActionSupport 
{
	public String addform()
	{
		this.LOG.info("cccccc");
		return "addform";
		
	}
	public String add()
	{
		this.LOG.info("cccccc");
		persondao dao = new persondao();
		dao.insert(vo);
		
		java.util.ArrayList<person> list = shopcar();
		list.add(vo);			
		return "add";
	}
	public String list() throws Exception
	{
		//this.setRslist(shopcar());
		return "list" ;
	}
	
	public String updateform() throws Exception
	{
		this.setVo(shopcar().get(index));
		return "updateform" ;
	}
	
	public String update() throws Exception
	{
		java.util.ArrayList<person> list =shopcar();
		list.set(index, vo);
		return "update" ;
	}
	
	public String delform() throws Exception
	{
		java.util.ArrayList<person> list =shopcar();
		list.remove(index);
		return list() ;
	}
	
	
	//java.util.ArrayList<person> rslist;
	
	public java.util.ArrayList<person> getRslist() {
		return shopcar(); //rslist;
	}
	//public void setRslist(java.util.ArrayList<person> rslist) {
		//this.rslist = rslist;
	//}

	person vo ;

	public person getVo() {
		return vo;
	}
	public void setVo(person vo) {
		this.vo = vo;
	}
	
	java.util.ArrayList<person> shopcar()
	{
		HttpSession session = ServletActionContext.getRequest().getSession();
		java.util.ArrayList<person> list = (java.util.ArrayList<person>)session.getAttribute("list");
		if(list == null)
		{
			list = new java.util.ArrayList<person>();
			session.setAttribute("list", list);			
		}
		return list;
	}
	
	int index ;

	public int getIndex() {
		return index;
	}
	public void setIndex(int index) {
		this.index = index;
	}
}
